package com.itheima.test02;

import java.util.Scanner;

public class Test_005 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int [] nums = new int[n];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = sc.nextInt();
            }
            //int[] nums = {1, 8, 9, 10, 7, 5};
            int s = findPeakElement(nums);
            System.out.println(s);
        }

        public static int findPeakElement(int[] nums) {
            //二分法
            //由于两端都是负无穷，因此只要左右两端任一端比中点大，意味着那一侧有峰
            int left = 0;
            int right = nums.length - 1;
            while (left < right) {
                int mid = left + (right - left) / 2;
                //最后的结果，left 和right相邻且nums[left]比左边大，nums[right]比右边大
                //故这二者的最大值即为峰值，返回其下标即可
                if (mid == left) {
                    return nums[right] > nums[left] ? right : left;
                }
                if (nums[mid] < nums[mid + 1]) {
                    left = mid;
                } else if (nums[mid] > nums[mid + 1]) {
                    right = mid;
                }
                mid = left + (right - left) / 2;
            }
            return 0;
        }
    }



